package com.cms.setting.banner.service.impl;


import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cms.framework.utils.BeanUtilEx;
import com.cms.framework.utils.page.PageView;
import com.cms.setting.banner.dao.BannerDAO;
import com.cms.setting.banner.pojo.Banner;
import com.cms.setting.banner.pojo.dto.BannerDTO;
import com.cms.setting.banner.service.BannerService;
import com.cms.setting.friendlink.pojo.Friendlink;
import com.cms.setting.friendlink.pojo.dto.FriendlinkDTO;
@Service
public class BannerServiceImpl implements BannerService {
	@Autowired
	BannerDAO bannerDAO;
	@Override
	public boolean saveBanner(Banner banner) {
		boolean flag=false;
		if(banner.getId()==null){
			flag=bannerDAO.insert(banner)>0;
		}else{
			flag=bannerDAO.updateByPrimaryKey(banner)>0;
		}
		return flag;
	}

	@Override
	public boolean deleteBanner(Integer Id) {
		if(Id != null && Id>0){
			return bannerDAO.deleteByPrimaryKey(Id)>0;
		}else{
			return false;
		}
	}
	
	@Override
	public Banner findByID(Integer Id) {
		return bannerDAO.selectByPrimaryKey(Id);
	}

	@Override
	public PageView<BannerDTO> findBannerPageList(
			PageView<BannerDTO> pageView, BannerDTO bannerDTOParams) {
		List<Banner> list=bannerDAO.findPageList(pageView, bannerDTOParams);
		List<BannerDTO> dtoList=new ArrayList<BannerDTO>();
		for(Banner banner:list){
			BannerDTO bannerDTO=new BannerDTO();
			try {
				BeanUtilEx.copyProperties(bannerDTO, banner);
				//friendlinkDTO.setPcUrl("pcUrl");
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			}
			dtoList.add(bannerDTO);
		}
		pageView.setRecords(dtoList);
		return pageView;
	}

}
